#ifndef TCPSOCKET_H
#define TCPSOCKET_H

#include <iostream>
#include <map>
#include <queue>
#include <functional>

#include "handler.h"

#define BUFF_SIZE 1024

typedef std::function<void(char*)> RecvCallback;

class EventLoop;

class TcpSocket: public Handler
{
public:
    TcpSocket(EventLoop *loop, int fd);
    ~TcpSocket();

    void sendData(const char *msg);
    void createRecvCallback(RecvCallback cb);

protected:
    EventLoop *m_evLoop;
    std::queue<std::string> m_sendQueue;

private:
    char m_recvBuff[BUFF_SIZE];
    char m_sendBuff[BUFF_SIZE];
    void readCallback(void);
    void writeCallback(void);
    RecvCallback m_recvFunc;
};

typedef TcpSocket* TcpSocketPtr;
typedef std::map<int, TcpSocketPtr> TCPSocketMap; //fd, TCPSocket*

#endif // TCPSOCKET_H
